gtkmountoperation: Drop the new line character when splitting a message
authorOndrej Holy <oholy@redhat.com>
Fri, 7 Aug 2020 07:38:37 +0000 (09:38 +0200)
committerOndrej Holy <oholy@redhat.com>
Fri, 7 Aug 2020 08:37:19 +0000 (10:37 +0200)
When asking for a password, the message string is split on primary
and secondary if it contains a newline character. However, the newline
character is currently part of both strings, which creates weird
spacing between the GtkLabels. I suppose this is bug, which was not
visible as in most cases (if not all) the message string hasn't
contained the new line characters so far. But we are going to change
that now, see GNOME/gvfs!82. Let's drop the new line character similarly
as it is done when asking for a question, or showing processes in order
to fix the weird spacing.

gtk/gtkmountoperation.c

index 20dc09b097e921a6d3d4ba71c5d15743262d70b7..674ab151922013372a93ad9c0b1fae94401dde7e 100644 (file)
@@ -576,7 +576,7 @@ gtk_mount_operation_ask_password_do_gtk (GtkMountOperation *operation,
   gboolean   can_anonymous;
   guint      rows;
   char *primary;
-  const char *secondary;
+  const char *secondary = NULL;
   PangoAttrList *attrs;
   gboolean use_header;
 
@@ -625,17 +625,14 @@ gtk_mount_operation_ask_password_do_gtk (GtkMountOperation *operation,
   main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 18);
   gtk_box_append (GTK_BOX (hbox), main_vbox);
 
-  secondary = strstr (message, "\n");
-  if (secondary != NULL)
-    {
-      primary = g_strndup (message, secondary - message + 1);
-    }
-  else
+  primary = strstr (message, "\n");
+  if (primary)
     {
-      primary = g_strdup (message);
+      secondary = primary + 1;
+      primary = g_strndup (message, primary - message);
     }
 
-  label = gtk_label_new (primary);
+  label = gtk_label_new (primary != NULL ? primary : message);
   gtk_widget_set_halign (label, GTK_ALIGN_START);
   gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
   gtk_label_set_wrap (GTK_LABEL (label), TRUE);